<template>
  <div>
    <div class="sys-user-container">
      <el-container>
        <el-main>
          <el-row>
            <el-form
                :inline="true"
                size="small"
                :model="formInline"
                class="demo-form-inline"
                @keyup.enter.native="search"
                @submit.native.prevent>
              <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    @click="sysUserOpenCreateDialog"
                    v-if="permissions.indexOf('user_sysUser_add') > -1">添加
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-input v-model="sysUserPageData.query.username" placeholder="请输入账号"/>
              </el-form-item>
              <el-form-item>
                <el-select
                    v-model="sysUserPageData.query.orgName"
                    placeholder="请选择部门"
                    clearable
                    @clear="clearId"
                    popper-class="select-box change-Option-width"
                    ref="selectBoxSearch">
                  <el-option>
                    <el-tree
                        node-key="id"
                        class="filter-tree"
                        :data="departmentData"
                        :props="defaultProps"
                        default-expand-all
                        highlight-current
                        ref="tree"
                        @node-click="handleSearchNodeClick"/>
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="permissions.indexOf('user_sysUser_addRole') > -1">
                <el-select
                    v-model="sysUserPageData.query.role"
                    popper-class="change-Option-width"
                    class="full-width"
                    clearable
                    placeholder="请选择角色"
                    @change="selectClick()">
                  <el-option
                      v-for="item in roleList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"/>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button icon="el-icon-search" type="primary" @click="search">查询</el-button>
                <el-button class="margin-left-10" icon="el-icon-delete" @click="sysUserReset">清空</el-button>
              </el-form-item>
              <el-tooltip effect="dark" content="刷新" placement="top-start">
                <el-button
                    size="small"
                    class="float-right"
                    icon="el-icon-refresh"
                    @click="search"
                    circle/>
              </el-tooltip>
            </el-form>
          </el-row>
          <el-table
              border
              stripe
              size="mini"
              :data="userList"
              ref="sysDictTable"
              style="width: 100%">
            <el-table-column label="序号" width="80" align="center">
              <template slot-scope="scope">
                <span>{{scope.$index+(sysUserPageData.pageInfo.currentPage - 1) * sysUserPageData.pageInfo.pageSize + 1}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="username" label="账号" align="center" show-overflow-tooltip/>
            <el-table-column prop="realName" label="用户名" align="center" show-overflow-tooltip/>
            <el-table-column prop="secret" label="密级" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                <span v-if="scope.row.secret == 1">公开</span>
                <span v-if="scope.row.secret == 2">内部</span>
                <span v-if="scope.row.secret == 3">秘密</span>
                <span v-if="scope.row.secret == 4">机密</span>
                <span v-if="scope.row.secret == 5">绝密</span>
              </template>
            </el-table-column>
            <el-table-column prop="orgName" label="部门" align="center" show-overflow-tooltip/>
            <el-table-column prop="roleName" label="角色" align="center" show-overflow-tooltip/>
            <el-table-column label="锁定状态" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag size="mini" :type="scope.row.lockFlag=='1' ? 'success' : 'danger'">
                  {{scope.row.lockFlag=='1' ? '有效' : '锁定'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="启用状态" align="center" show-overflow-tooltip>
              <template slot-scope="scope">
                <el-tag size="mini" :type="scope.row.enable=='1' ? 'success' : 'danger'">
                  {{scope.row.enable=== 1 ? '启用' : '停用'}}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="400px" align="center">
              <template slot-scope="scope">
                <el-button
                    type="text"
                    size="small"
                    icon="el-icon-view"
                    v-if="permissions.indexOf('user_sysUser_query') > -1"
                    @click="look(scope.row)">
                  查看
                </el-button>
                <el-button
                    type="text"
                    icon="el-icon-edit"
                    size="small"
                    @click="sysUserOpenUpdateDialog(scope.row)"
                    v-if="permissions.indexOf('user_sysUser_edit') > -1">修改
                </el-button>
                <el-button
                    type="text"
                    icon="el-icon-delete"
                    @click="sysUserDeleteRecord(scope.row)"
                    v-if="permissions.indexOf('user_sysUser_del') > -1 && scope.row.isEdit">删除
                </el-button>
                <el-button
                    type="text"
                    icon="el-icon-edit"
                    size="small"
                    @click="deblocking(scope.row)"
                    v-if="scope.row.lockFlag === 2 && permissions.indexOf('user_sysUser_deblocking') > -1">解锁
                </el-button>
                <el-button
                    type="text"
                    icon="el-icon-view"
                    size="small"
                    @click="personDetail(scope.row)"
                    v-if="scope.row.card">人员信息
                </el-button>
                <el-button
                    type="text"
                    size="small"
                    v-if="permissions.indexOf('user_sysUser_enable') > -1"
                    :icon="scope.row.enable === 1 ? 'el-icon-lock': 'el-icon-unlock'"
                    @click="enable(scope.row)">{{scope.row.enable === 1 ? '停用' : '启用'}}
                </el-button>
                <el-button
                    type="text"
                    size="small"
                    icon="el-icon-refresh"
                    v-if="permissions.indexOf('user_sysUser_resetPwd') > -1"
                    @click="resetPwd(scope.row)">重置密码
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="end" v-show="sysUserPageData.pageInfo.totalRecordCount>0">
            <el-pagination
                class="pageBar"
                :style="{float: 'right', padding: '20px'}"
                background
                @size-change="sysUserSizeChange"
                @current-change="sysUserCurrentChange"
                :current-page="sysUserPageData.pageInfo.currentPage"
                :page-sizes="[5, 10, 20, 30]"
                :page-size="sysUserPageData.pageInfo.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="sysUserPageData.pageInfo.totalRecordCount"></el-pagination>
          </el-row>
        </el-main>
      </el-container>
      <el-dialog
          customClass="userIndex"
          :title="sysUserDialogData.sysUserTitle"
          :visible.sync="sysUserDialogData.visible"
          width="600px"
          append-to-body="true"
          @close="cancelDialog"
          :close-on-click-modal="false"
      >
        <el-container>
          <el-main>
            <el-form
                ref="sysUserForm"
                :rules="rules"
                :model="sysUserDialogData.sysUserFormData"
                label-width="80px"
            >
              <el-form-item label="账号" prop="username">
                <el-input
                    placeholder="请输入账号"
                    @blur="usernameBlur"
                    :disabled="isLook || sysUserDialogData.sysUserTitle === '修改'"
                    v-model="sysUserDialogData.sysUserFormData.username"
                />
              </el-form-item>
              <el-form-item label="用户名" prop="realName">
                <el-input
                    placeholder="请输入用户名"
                    :disabled="isLook"
                    v-model="sysUserDialogData.sysUserFormData.realName"
                />
              </el-form-item>
              <el-form-item label="密级:" prop="secret" class="width-100">
                <el-select
                    :disabled="isLook"
                    v-model="sysUserDialogData.sysUserFormData.secret"
                    placeholder="请选择"
                    style="width: 100%">
                  <el-option
                      v-for="item in secretList"
                      :key="item.type"
                      :label="item.name"
                      :value="item.type"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="部门" prop="orgId" class="form-item-tree">
                <el-select
                    :disabled="isLook"
                    v-model="sysUserDialogData.sysUserFormData.orgName"
                    placeholder="请选择部门"
                    popper-class="select-box change-Option-width"
                    ref="selectBox"
                >
                  <el-option>
                    <el-tree
                        node-key="id"
                        class="filter-tree"
                        :data="departmentData"
                        :props="defaultProps"
                        default-expand-all
                        highlight-current
                        ref="tree"
                        @node-click="handleDepartmentNodeClick"
                    ></el-tree>
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="角色" prop="role">
                <!-- v-if="permissions.indexOf('user_sysUser_addRole') > -1" -->
                <el-select
                    v-model="sysUserDialogData.sysUserFormData.role"
                    filterable
                    :disabled="isLook"
                    popper-class="change-Option-width"
                    class="full-width"
                    placeholder="请选择角色"
                    @change="$forceUpdate()"
                >
                  <el-option
                      v-for="item in roleList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态" prop="lockFlag">
                <el-radio-group
                    :disabled="true"
                    v-model="sysUserDialogData.sysUserFormData.lockFlag"
                >
                  <el-radio :label="1">有效</el-radio>
                  <el-radio :label="2">锁定</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item
                  v-if="this.sysUserDialogData.sysUserTitle=='添加'"
                  label="密码"
                  prop="password"
              >
                <el-input
                    placeholder="请输入密码"
                    :maxlength="maxPwdLength"
                    :disabled="isLook"
                    type="password"
                    v-model="sysUserDialogData.sysUserFormData.password"
                />
              </el-form-item>
              <el-form-item
                  v-if="this.sysUserDialogData.sysUserTitle=='添加'"
                  label="确认密码"
                  prop="password2"
              >
                <el-input
                    placeholder="请输入再次输入密码"
                    :maxlength="maxPwdLength"
                    :disabled="isLook"
                    type="password"
                    v-model="sysUserDialogData.sysUserFormData.password2"
                />
              </el-form-item>
            </el-form>
          </el-main>
        </el-container>
        <div slot="footer" class="dialog-footer" v-show="!isLook">
          <el-button
              icon="el-icon-circle-plus-outline"
              size="small"
              @click="sysUserSaveOrUpdate"
              type="primary"
          >确 定
          </el-button>
          <el-button icon="el-icon-circle-close" size="small" @click="cancelDialog">取 消</el-button>
        </div>
      </el-dialog>

      <el-dialog
          customClass="userIndex"
          :title="personDetailTitle"
          :visible.sync="personDetailVisable"
          width="600px"
          append-to-body="true"
          @close="cancelPersonDialog"
          :close-on-click-modal="false"
      >
        <el-container>
          <el-main>
            <el-form
                label-width="80px"
            >
              <el-form-item label="名称">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.name"
                />
              </el-form-item>
              <el-form-item label="身份证号">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.card"
                />
              </el-form-item>
              <el-form-item label="学历">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.education"
                />
              </el-form-item>
              <el-form-item label="民族">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.nationality"
                />
              </el-form-item>
              <el-form-item label="性别">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.sex"
                />
              </el-form-item>
              <el-form-item label="出生日期">
                <el-input
                    style="width:250px"
                    :disabled="false"
                    v-model="personData.birthDate"
                />
              </el-form-item>
            </el-form>
          </el-main>
        </el-container>
      </el-dialog>

    </div>
  </div>
</template>

<script>
import sysUserApi from "./api/sysUser.service";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Mixins from "@/puzzles/tpf/mixins/index";

export default {
  mixins: [Mixins],
  components: {
    Treeselect,
  },
  data() {
    var validateIdNumber = (rule, value, callback) => {
      if (value !== "") {
        console.log(this.minPwdLength, this.maxPwdLength);
        if (value.length >= this.minPwdLength && value.length <= this.maxPwdLength) {
          // 数字和字母组合的正则
          var reg = /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z]{8,}$/;
          //  数字和字母和特殊符合组合 正则
          var reg1 = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*?])[\da-zA-Z~!@#$%^&*?]{8,}$/;
          //var reg = /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)])+$)(?!^.*[\u4E00-\u9FA5].*$)^\S{8,}$/;
          if (reg.test(value) === true || reg1.test(value) === true) {
            callback();
          } else {
            callback(
              new Error(
                // `密码为英文字母、数字和特殊字符的组合，${this.minPwdLength}到${this.maxPwdLength}个字符！`
                `口令长度${this.minPwdLength}到${this.maxPwdLength}位，且至少为数字和字母的组合，仅支持特殊字符：~!@#$%^&*?`
              )
            );
          }
        } else {
          // 字符长度不匹配
          callback(
            new Error(
              // `密码为英文字母、数字和特殊字符的组合，${this.minPwdLength}到${this.maxPwdLength}个字符！`
              `口令长度${this.minPwdLength}到${this.maxPwdLength}位，且至少为数字和字母的组合，仅支持特殊字符：~!@#$%^&*?`
            )
          );
        }
      } else {
        callback();
      }
    };
    return {
      personDetailTitle: "",
      personDetailVisable: false,
      personData: {
        name: "",
        card: "",
        education: "",
        nationality: "",
        birthDate: "",
        sex: "",
      },
      rules: {
        role: [{required: true, message: "角色不能为空！", trigger: "blur"}],
        realName: [
          {required: true, message: "用户名不能为空！", trigger: "blur"},
          {
            min: 1,
            max: 10,
            message: "用户名在 1 到 10 个字符",
            trigger: "blur",
          },
        ],
        username: [
          {required: true, message: "账号不能为空！", trigger: "blur"},
          {
            pattern: /^[0-9a-zA-Z]{1,}$/,
            message: "账号只能是字母或数字！",
            trigger: "blur",
          },
          {
            min: 1,
            max: 10,
            message: "账号在 1 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [
          {required: true, message: "密码不能为空！", trigger: "blur"},
          // {
          //   pattern: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)$/,
          //   message: `密码必须含有大小写字母和数字${this.pwdLength} 个字符！`,
          //   trigger: "blur",
          // },
          {
            validator: validateIdNumber,
            trigger: "blur",
          },
        ],
        password2: [
          {required: true, message: "确认密码不能为空！", trigger: "blur"},
          {
            validator: validateIdNumber,
            trigger: "blur",
          },
        ],
        orgId: [
          {required: true, message: "部门不能为空！", trigger: "change"},
        ],
        // role: [{ required: true, message: "角色不能为空！", trigger: "blur" }],
        secret: [{required: true, message: "用户密级不能为空！", trigger: "blur"}],

      },
      permissions: JSON.parse(sessionStorage.getItem("permissions")),
      formInline: {
        user: "",
        region: "",
      },
      isLook: false,
      departmentData: [
        {
          id: 1,
          label: "一级部门",
          children: [
            {
              id: 2,
              label: "二级部门",
              children: [
                {
                  label: "三级部门",
                },
              ],
            },
          ],
        },
      ],
      currentNode: null,
      defaultProps: {
        children: "children",
        label: "name",
      },
      roleList: [],
      // readOnly: true,
      sysUserSelectIds: [],
      sysUserDialogData: {
        visible: false,
        sysUserTitle: "",
        sysUserFormData: {
          realName: "",
          username: "",
          password: "",
          password2: "",
          orgName: "",
          role: "",
          secret: "",
          lockFlag: 1,
          orgId: null,
        },
      },
      filterText: "",
      sysUserPageData: {
        query: {
          username: "",
          orgName: "",
          orgId: "",
          role: null,
        },
        pageInfo: {
          pageSize: 10,
          currentPage: 1,
          totalRecordCount: 0,
        },
      },
      userList: [],
      minPwdLength: 0,
      maxPwdLength: 0,
      secretList: [
        {
          type: 1,
          name: "公开"
        },
        {
          type: 2,
          name: "内部"
        },
        {
          type: 3,
          name: "秘密"
        },
        {
          type: 4,
          name: "机密"
        },
        {
          type: 5,
          name: "绝密"
        },
      ]
    };
  },
  created() {
    this.sysUserQuery(this.sysUserPageData.pageInfo);
    this.getRoleList();
    this.getOrgTree();
    this.initPwdLength()
  },
  methods: {
    usernameBlur() {
    },
    initPwdLength() {
      sysUserApi.getSafePolicy().then((res) => {
        if (res.code !== 10200) return this.$message.error(res.msg);
        this.minPwdLength = Number(res.data.sysPassShortLength);
        this.maxPwdLength = Number(res.data.sysPassLength);
      });
    },
    look(row) {
      this.sysUserDialogData.visible = true;
      this.sysUserDialogData.sysUserTitle = "查看";
      this.isLook = true;
      this.sysUserDialogData.sysUserFormData = JSON.parse(JSON.stringify(row));
    },
    del(row) {
      this.$confirm("本操作将永久删除，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    handleDepartmentNodeClick(data) {
      this.sysUserDialogData.sysUserFormData.orgId = data.id;
      this.sysUserDialogData.sysUserFormData.orgName = data.name;
      this.$refs.selectBox.blur();
    },
    handleSearchNodeClick(data) {
      this.sysUserPageData.query.orgName = data.name;
      this.sysUserPageData.query.orgId = data.id;
      this.$refs.selectBoxSearch.blur();
    },
    selectClick(val) {
    },
    cancelDialog() {
      let obj = {
        realName: "",
        username: "",
        password: "",
        orgName: "",
        role: "",
        lockFlag: 1,
        orgId: null,
      };
      this.sysUserDialogData.sysUserFormData = obj;
      this.$refs["sysUserForm"].resetFields();
      this.sysUserDialogData.visible = false;
      this.isLook = false;
    },
    getRoleList() {
      let _this = this;
      sysUserApi.getSysRoleList().then((res) => {
        _this.roleList = res.data;
      });
    },
    getOrgTree() {
      let _this = this;
      sysUserApi.getSysOrgTree().then((res) => {
        _this.departmentData = this.leafNoChildren(res.data);
      });
    },
    search() {
      this.sysUserPageData.pageInfo.currentPage = 1;
      this.sysUserQuery(this.sysUserPageData.pageInfo);
    },
    /**
     * 用户查询
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserQuery(page) {
      let _this = this;
      let params = {
        currentPage: page.currentPage,
        pageSize: page.pageSize,
      };
      sysUserApi
        .getSysUserPage(Object.assign(params, this.sysUserPageData.query))
        .then((res) => {
          _this.sysUserPageData.pageInfo.totalRecordCount = res.data.totalRecordCount;
          let userList = res.data.records;
          if (userList && userList.length > 0) {
            userList.forEach(function (user) {
              let roleName = "", roleIdData;
              if (user.roleList && user.roleList.length > 0) {
                // roleArray = [];
                user.roleList.forEach(function (role, index) {
                  // roleArray.push(role.id);
                  roleIdData = role.id
                  index === user.roleList.length - 1 ? (roleName += role.description) : (roleName += role.description + ",");
                });
              }
              user.role = roleIdData;
              user.roleName = roleName;
              user.lockFlag = parseInt(user.lockFlag);
            });
          }
          _this.userList = userList;
        });
    },
    /**
     * 用户查询重置
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserReset() {
      this.sysUserPageData.query.username = "";
      this.filterText = "";
      this.sysUserPageData.query.orgId = "";
      this.sysUserPageData.query.orgName = "";
      this.sysUserPageData.query.role = "";
      this.search();
    },

    /**
     * 用户页码变化
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserSizeChange(val) {
      this.sysUserPageData.pageInfo.pageSize = val;
      this.sysUserQuery(this.sysUserPageData.pageInfo);
    },

    /**
     * 用户当前页
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserCurrentChange(val) {
      this.sysUserPageData.pageInfo.currentPage = val;
      this.sysUserQuery(this.sysUserPageData.pageInfo);
    },

    /**
     * 用户列表选中事件
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserSelectionChange(selection) {
      this.sysUserSelectIds = [];
      selection.forEach((item, index) => {
        this.sysUserSelectIds.push(item.id);
      });
    },

    /**
     * 用户添加
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserOpenCreateDialog() {
      this.sysUserDialogData.sysUserTitle = "添加";
      this.sysUserDialogData.visible = true;
      this.rules.password[0].required = true;
      this.sysUserDialogData.sysUserFormData = {
        realName: "",
        username: "",
        password: "",
        orgId: null,
        orgName: "",
        role: null,
        lockFlag: 1,
      };
    },

    /**
     * 用户修改
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserOpenUpdateDialog(row) {
      this.sysUserDialogData.sysUserTitle = "修改";
      this.sysUserDialogData.visible = true;
      this.rules.password[0].required = false;
      this.sysUserDialogData.sysUserFormData = JSON.parse(JSON.stringify(row));
      this.$nextTick(function () {
        this.$refs.tree.setCurrentKey(row.orgId);
      });
    },
    /**
     * 解锁用户信息
     */
    deblocking(row) {
      let _this = this;
      sysUserApi.deblockingUser(row.id).then((res) => {
        if (res.code == 10200) {
          this.$message.success("解锁成功！");
          _this.search();
        } else {
          this.$message.error(res.msg);
        }
      });
    },

    /**
     * 人员信息
     * */
    personDetail(row) {
      let _this = this;
      this.personDetailTitle = "查看人员详细信息";
      this.personDetailVisable = true;
      sysUserApi.personDetail(row.card).then((res) => {
        if (res.code == 10200) {
          this.personData = res.data;
        } else {
          this.$message.error(res.msg);
        }
      });
    },

    /**
     *
     * 查看人员详细
     * */
    cancelPersonDialog() {
      this.personData = {};
      this.personDetailVisable = false;
    },
    /**
     * 用户保存
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserSaveOrUpdate() {
      let _this = this;
      this.$refs["sysUserForm"].validate((valid) => {
        if (valid) {
          let params = {
            id: this.sysUserDialogData.sysUserFormData.id,
            lockFlag: this.sysUserDialogData.sysUserFormData.lockFlag,
            orgId: this.sysUserDialogData.sysUserFormData.orgId,
            role: this.sysUserDialogData.sysUserFormData.role,
            username: this.sysUserDialogData.sysUserFormData.username,
            secret: this.sysUserDialogData.sysUserFormData.secret,
            realName: this.sysUserDialogData.sysUserFormData.realName,
          };
          if (this.sysUserDialogData.sysUserFormData.id) {
            sysUserApi.updateSysUserById(params).then((res) => {
              if (res.data) {
                this.$message.success("修改成功！");
                _this.sysUserDialogData.visible = false;
                _this.search();
              } else {
                this.$message.error(res.msg);
              }
            });
          } else {
            if (
              this.sysUserDialogData.sysUserFormData.password !==
              this.sysUserDialogData.sysUserFormData.password2
            ) {
              this.$message.error("两次输入密码不同请重新输入");
              return false;
            }
            let params = {
              realName: this.sysUserDialogData.sysUserFormData.realName,
              username: this.sysUserDialogData.sysUserFormData.username,
              password: this.sysUserDialogData.sysUserFormData.password,
              orgName: this.sysUserDialogData.sysUserFormData.orgName,
              role: this.sysUserDialogData.sysUserFormData.role,
              lockFlag: this.sysUserDialogData.sysUserFormData.lockFlag,
              orgId: this.sysUserDialogData.sysUserFormData.orgId,
              secret: this.sysUserDialogData.sysUserFormData.secret,
            };
            sysUserApi.saveSysUser(params).then((res) => {
              if (res.code == 10200) {
                this.$message.success("添加成功！");
                _this.sysUserDialogData.visible = false;
                _this.search();
              } else {
                this.$message.error(res.msg);
              }
            });
          }
        } else {
          return false;
        }
      });
    },

    /**
     * 用户删除
     * @author wangwuhui
     * @date 2020-03-25 14:55:03
     */
    sysUserDeleteRecord(data) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        sysUserApi.deleteSysUser(data.id).then((res) => {
          if (res.code === 10200) {
            this.$message({
              type: "success",
              message: "用户删除成功!",
            });
            this.search();
          } else if (res.code === 10400) {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
        });
      });
    },
    // 清除部门id
    clearId() {
      console.log(this.sysUserPageData.query);
      this.sysUserPageData.query.orgId = null;
    },

    /**
     * 启用停用用户
     */
    enable(row) {
      let _this = this;
      let msg = "";
      let enable = "";
      console.log(row.enable)
      if (row.enable === 1) {
        msg = "停用";
        enable = 2;
      }
      if (row.enable === 2) {
        msg = "启用";
        enable = 1;
      }
      let params = {
        id: row.id,
        enable: enable,
      };
      sysUserApi.enable(params).then((res) => {
        if (res.data) {
          this.$message.success(msg + "成功！");
          _this.sysUserDialogData.visible = false;
          _this.search();
        } else {
          this.$message.error(res.msg + "失败！");
        }
      });
    },

    /**
     * 重置密码
     */
    resetPwd(row) {
      let _this = this;
      let params = {
        id: row.id,
      };
      sysUserApi.resetPwd(params).then((res) => {
        console.log(params)
        if (res.data) {
          this.$message.success("重置密码成功！");
          _this.search();
        } else {
          this.$message.error("重置密码失败！");
        }
      });
    },
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
};
</script>

<style scoped lang="less">
  .float-left {
    float: left;
  }

  .float-right {
    float: right;
  }

  .margin-top-20 {
    margin-top: 20px;
  }

  .margin-bottom-10 {
    margin-bottom: 10px;
  }

  .margin-left-10 {
    margin-left: 10px;
  }

  .over-flow-hidden {
    overflow: hidden;
  }

  .full-width {
    width: 100%;
  }
</style>
<style>
  .userIndex .el-dialog__body {
    padding-bottom: 0;
  }
</style>
